const baseURL = "https://admin.yunshuicha.com/api" // https://admin.yunshuicha.com/api http://127.0.0.1:888
const httpRequest = function($p) {
	if (!$p || !$p.url) {
		return;
	}
	let _h = {
		token: uni.getStorageSync('token')
	}
	if ($p.header) {
		for (let k in $p.header) {
			_h[k] = $p.header[k]
		}
	}
	uni.showLoading({
		mask: true
	})
	uni.request({
		url: baseURL + $p.url,
		method: $p.method || 'GET',
		header: _h,
		data: $p.data,
		success: function(res) {
			uni.hideLoading()
			let data = res.data
			if (data.code === 0 || data.success == true) {
				$p.fn(data.data)
			} else {
				uni.showToast({
					title: data.msg || data.message,
					duration: 5000,
					icon: 'none'
				})
			}
		},
		fail: function(e) {
			console.warn(e)
			uni.hideLoading()
			uni.showToast({
				title: '接口404',
				icon: 'error',
				duration: 3000
			})
		},
		complete: function() {

		}
	})
};
export default {
	baseURL,
	httpRequest
}
